[NSLocale currentLocale] always returns "en_US" not user's current language

Posted by Prairiedogg on Stack Overflow See other posts from Stack Overflow or by Prairiedogg
Published on 2009-10-05T20:28:56Z Indexed on 2010/03/18 4:21 UTC
Read the original article Hit count: 675

Filed under:
|
|
|

I'm in the processes of internationalizing an iPhone app - I need to make programmatic changes to certain views based on what the user's current locale is. I'm going nuts because no matter what the language preference on the iPhone simulator or actual hardware are, locale always evaluates to "en_US":

NSString *locale = [[NSLocale currentLocale] localeIdentifier];
NSLog(@"current locale: %@", locale);

The crazy thing is that the rest of the application behaves as expected. The correct strings are selected from the Localization.strings file and used in the interface, and the correct .xib files for the selected locale are used.

I have also tried the following, to no avail and with the same result:

NSString *locale = [[NSLocale autoupdatingCurrentLocale] localeIdentifier];
NSLog(@"current locale: %@", locale);

Is there something simple I'm missing? A preference or an import perhaps?

Update:

As Darren's answer suggests, the preference I'm looking for is not in NSLocale, rather it is here:

NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
NSLog(@"preferredLang: %@", preferredLang);

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa